<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	</head>
	<body>
	<?php 
					$daction = $_SESSION['action'];
		include 'operations/connection.php';
		//Get information of document
		$query = mysql_query("select a.Tile,a.Content,e.Fullname,a.Timecreate,a.IDGroupApprove,a.comment,a.Location,a.EmployeePerforment,
				a.TripDate,a.TotalTime,a.Description,a.IDStatus
				from approvedoc a inner join employee e on a.IDEmployee = e.IDEmployee 
				where a.IDApproveDoc = '$id'");
		while ($row = mysql_fetch_array($query))
		{
			
			$dcomment = $row[comment];
			$dtitle = $row[Tile];
			$ddescription = $row[Description];
			$dtime = $row[Timecreate];
			$duser = $row[Fullname];
			$demployeeperforment = $row[EmployeePerforment];
			$dtripdate = $row[TripDate];
			$dlocation = $row[Location];
			$dtotaltime = $row[TotalTime];
			$didgroupapprover = $row[IDGroupApprove];
			$dcontent = $row[Content];
			$dstatus = $row[IDStatus];
		}
	?>
	<div class="main_content">
            <ul class="top_but">
				<li><a class="back-button"><img src="images/back.png" alt="" /></a><p class="hidden">Back</p></li>
				<?php if($daction=="re_not_approve"){?>
				<li><a href="<?echo approve($didgroupapprover, $id_employee)?>"><img src="images/approval.png" alt="" /></a><p class="hidden">Approve</p></li>
				<li><a href="<?echo reject($didgroupapprover, $id_employee)?>"><img src="images/reject.png" alt="" /></a><p class="hidden">Reject</p></li>
				<?php }?>
				<?php
					if($daction == "re_reference_waiting"){
				?>
					<li><a href="<?echo viewReference($didgroupapprover, $id_employee)?>"><img src="images/approval.png" alt="" /></a><p class="hidden">Accept</p></li>
				<?php }?>
			</ul>
            <table class="tcontent" cellpadding="5" cellspacing="0">
                <tr>
                	<td class="col_left" width="15%"><?=$l_approver?></td>
                    <td colspan="4">
                    	<table style="width: 100%;" cellpadding="5" cellspacing="0">
                    		<tr>
                    			<td><?=$l_step?></td>
                    			<td>
                    				<?
                    				//Get group approver
                    				$query1 = mysql_query("SELECT st.IDConfigStaticLang,l.DateApprove,e.Fullname FROM listapprove l
											INNER JOIN employee e ON l.IDEmployee = e.IDEmployee
											INNER JOIN `status` st ON l.IDStatus = st.IDStatus
                    						WHERE CONVERT(l.IDGroupApprove USING utf8) = CONVERT('$didgroupapprover' USING utf8)
                    						ORDER BY l.Order ASC");
                    				while ($row = mysql_fetch_array($query1))
                    				{
                    					$dnameapprover = $row[Fullname];
                    					$ddateapproved = $row[DateApprove];
	                    				if ($row[IDConfigStaticLang] == 8){
	                    					$dstatus=$l_status_complete;
	                    				} else if ($row[IDConfigStaticLang] == 9){
	                    					$dstatus=$l_status_pending;
	                    				} else if ($row[IDConfigStaticLang] == 10){
	                    					$dstatus=$l_status_declined;
	                    				} else if ($row[IDConfigStaticLang] == 11){
	                    					$dstatus=$l_status_saved;
	                    				} else if ($row[IDConfigStaticLang] == 20){
	                    					$dstatus=$l_status_reference;
	                    				}
                    				?>
                    				<span style="display: block;">
                    					<b><?=$dnameapprover?></b>_<?=$dstatus?>_<?=$ddateapproved?>
                    				</span>
                    				<?
                    				}
                    				?>
                    			</td>
                    			<td>
                    				<?
                    				//Get list references
                    				$query2 = mysql_query("SELECT e.Fullname FROM list_reference l
                    						INNER JOIN employee e ON l.id_employee = e.IDEmployee
                    						WHERE CONVERT(l.id_group USING utf8) = CONVERT('$didgroupapprover' USING utf8)");
                    				while ($row = mysql_fetch_array($query2))
                    				{
                    					$dnamereferences = $row[Fullname];
                    				?>
                    				<b><?=$dnamereferences?></b>;
                    				<?
                    				}
                    				?>
                    			</td>
                    		</tr>
                    	</table>
                    </td>
                </tr>
                <tr>
                	<td class="col_left" width="15%"><?=$l_title?></td>
                    <td colspan="4"><?=$dtitle?></td>
                </tr>
                <tr>
                	<td class="col_left"><?=$l_description?></td>
                    <td colspan="4">
                   		<?=$ddescription?>
                   	</td>
                </tr>
                <tr>
                	<td class="col_left"><?=$l_created_date?></td>
                    <td>
                    	<?=$dtripdate?>
                    </td>
                	<td class="col_left"><?=$l_writer?></td>
	                    <td>
	                    	<?=$duser?>
	                    </td>
	                </tr>
                <tr>
                	<td class="col_left"><?=$l_employee_performent?></td>
                    <td>
                    	<?=$demployeeperforment?>
                    </td>
                    <td class="col_left"><?=$l_trip_date?></td>
                    <td>
                    	<?=$dcontent?>
                    </td>
                </tr>
                <tr>
                	<td class="col_left"><?=$l_location?></td>
                    <td>
                    	<?=$dlocation?>
                    </td>
                    <td class="col_left"><?=$l_total_time?></td>
                    <td>
                    	<?=$dtotaltime?>
                    </td>
                </tr>
            </table>
            <div class="content_doc"><?=$dcontent?></div>
            <table class="list_ref" cellpadding="5" cellspacing="0">
            	<tr>
            		<th style="width: 50px;"><?=$l_no?></th>
            		<th><?=$l_product_item?></th>
            		<th><?=$l_company_name?></th>
            		<th><?=$l_quantity?></th>
            		<th><?=$l_price?></th>
            		<th><?=$l_price_vat?></th>
            		<th><?=$l_total_amount?></th>
            	</tr>
            	<?
            	$querybuy = mysql_query("select * from buying_document where document_id = '$id'");
            	$dtotalamountt = 0;
            	while ($row = mysql_fetch_array($querybuy))
            	{
            		$dproductitem = $row[name];
            		$dcompanyname = $row[company];
            		$dquantity = $row[amount];
            		$dprice = $row[price];
            		$dpricevat = $row[vat];
            		$dtotalamount = $row[total];
            		$dtotalamountt = $dtotalamount + $dtotalamountt;
            	?>
            	<tr>
            		<td></td>
            		<td><?=$dproductitem?></td>
            		<td><?=$dcompanyname?></td>
            		<td><?=$dquantity?></td>
            		<td><?=$dprice?></td>
            		<td><?=$dpricevat?></td>
            		<td style="text-align: right;padding-right: 10px;"><?=$dtotalamount?></td>
            	</tr>
            	<?
            	}
            	?>
            </table>
            <table class="tcontent" cellpadding="5" cellspacing="0">
                <tr>
                	<td class="col_left" width="15%"><?=$l_total_amount?></td>
                    <td style="text-align: right;font-weight: bold;padding-right: 10px;"><?=$dtotalamountt?></td>
                </tr>
                <tr>
                	<td class="col_left"><?=$l_comment?></td>
                    <td style="text-align: left;">
                   		<?=$dcomment?>
                   	</td>
                </tr>
            </table>
      </div>
	</body>
    <?php mysql_close($connection);?>
</html>